#ifndef DYN_TRAPZDRIVER_H
#define DYN_TRAPZDRIVER_H

#include "../utilities/dyn_functor.h"

/*! \author Joey Dumont
 *
 *  \date 2012-10-05
 *
 *  \brief Returns the nth stage of refinement of the trapezoidal rule.
 *
 * This base class is used to compute refinements of the extended
 * trapezoidal rule. These are then used to define higher-order
 * methods through Richardson extrapolation.
 */

class TrapzDriver
{
public:
    /*! Constructor defines the function and the bounds
     * of integration. */
    TrapzDriver(Functor& _func,
                double _a,
                double _b);


    /*! @name Accessor Functions */
    //@{
    Functor& getFunctor(){return func;}
    double getA(){return a;}
    double getB(){return b;}

    void setFunctor(Functor& _func){func=_func;}
    void setA(double _a){a=_a;}
    void setB(double _b){b=_b;}
    //@}

    /*! We compute the next refinement. For \f$n=1\f$, we
     * simply compute \f$0.5(f(a)+f(b))\f$, i.e. the average
     * over the interval. For higher \f$n\f$, wwe add
     * \f$2^{n-2}\f$ interior points. */
    double computeNextRefinement();

protected:
    /*! @name Class Data */
    //@{
    Functor& func;
    double a;
    double b;
    /*! The value of the integral. */
    double s;
    /*! The value of the refinement. */
    int n;
    //@}

};

#endif // DYN_TRAPZDRIVER_H
